package com.buaa.model.solr;

import com.alibaba.fastjson.JSONObject;
import com.buaa.model.dto.ItemStyle;
import com.buaa.model.dto.Normal;
import com.buaa.model.dto.WordCloud;
import com.buaa.util.MathUtil;
import org.apache.solr.client.solrj.beans.Field;
import org.springframework.data.solr.core.mapping.SolrDocument;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DELL on 2018/4/13.
 */
@SolrDocument(solrCoreName="person")
public class Person {

    @Field("id")
    private String id;

    @Field("name_s")
    private String name;

    @Field("organization_s")
    private String organization;

    @Field("depart_s")
    private String department;

    @Field("edu_level_s")
    private String education_level;

    @Field("base_score_i")
    private double base_score;

    @Field("sex_s")
    private String sex;

    @Field("birthday_s")
    private String birthday;

    @Field("place_s")
    private String place;

    @Field("address_s")
    private String address;

    @Field("achievement_s")
    private String achievement;

    @Field("experience_s")
    private String experience;

    @Field("prize_s")
    private String prize;

    @Field("extra_s")
    private String extra;

    @Field("resource_url_s")
    private String resource_url;

    @Field("label_s")
    private String label;

    @Field("position_ss")
    private List<String> position;

    @Field("fields_ss")
    private List<String> fields;

    @Field("degree_ss")
    private List<String> degree;

    @Field("fields_weight_ds")
    private List<Double> fields_weight;

    private List<WordCloud> wordClouds = new ArrayList<>();


    public String getWordClouds() {

        if(fields_weight == null){
            return JSONObject.toJSON(new WordCloud()).toString();
        }
        List<Double> fieldss_weight_new = MathUtil.soft(fields_weight);

        for(int i=0;i<fieldss_weight_new.size() && i<fieldss_weight_new.size();i++){
            WordCloud wordCloud = new WordCloud();
            wordCloud.setName(fields.get(i));
            wordCloud.setValue(fieldss_weight_new.get(i)*20);
            ItemStyle itemStyle = new ItemStyle();
            Normal normal = new Normal();
            normal.init();
            itemStyle.setNormal(normal);
            wordCloud.setItemStyle(itemStyle);
            wordClouds.add(wordCloud);
        }
        if(wordClouds.size()>20){
            wordClouds = wordClouds.subList(0,20);
        }

        Object object = JSONObject.toJSON(wordClouds);
        String objectstr = object.toString();

        return objectstr;
    }

    public void setWordClouds(List<WordCloud> wordClouds) {
        this.wordClouds = wordClouds;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOrganization() {
        return organization;
    }

    public void setOrganization(String organization) {
        this.organization = organization;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getEducation_level() {
        return education_level;
    }

    public void setEducation_level(String education_level) {
        this.education_level = education_level;
    }

    public double getBase_score() {
        return base_score;
    }

    public void setBase_score(double base_score) {
        this.base_score = base_score;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAchievement() {
        return achievement;
    }

    public void setAchievement(String achievement) {
        this.achievement = achievement;
    }

    public String getExperience() {
        return experience;
    }

    public void setExperience(String experience) {
        this.experience = experience;
    }

    public String getPrize() {
        return prize;
    }

    public void setPrize(String prize) {
        this.prize = prize;
    }

    public String getExtra() {
        return extra;
    }

    public void setExtra(String extra) {
        this.extra = extra;
    }

    public String getResource_url() {
        return resource_url;
    }

    public void setResource_url(String resource_url) {
        this.resource_url = resource_url;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public List<String> getPosition() {
        return position;
    }

    public void setPosition(List<String> position) {
        this.position = position;
    }

    public void setFields(List<String> fields) {
        this.fields = fields;
    }

    public List<String> getDegree() {
        return degree;
    }

    public void setDegree(List<String> degree) {
        this.degree = degree;
    }

    public void setFields_weight(List<Double> fields_weight) {
        this.fields_weight = fields_weight;
    }

    public List<String> getFields() {
        return fields;
    }

    public List<Double> getFields_weight() {
        return fields_weight;
    }
}
